<?php
//判断是否正当访问
if(!defined('IN_DISCUZ') || empty($_G['uid']) || empty($_G['gp_tid'])) {
	exit('Access Denied');
}

require_once DISCUZ_ROOT.'./source/plugin/donkey_activity/donkey_activity.func.php';
//判断活动状态，访问权限
$activity = get_activity('', 'manager');

//判断是否有人报名成功
$query = DB::fetch_first('SELECT count(*) c from '.DB::table('donkey_activity_apply').' WHERE verified=1 and tid='.$_G['gp_tid']);
if(empty($query) || $query['c'] < 1){
	showmessage('没有一个报名成功的会员');
}

//输出excel文件
$subject = $activity['subject'];
$filename = (preg_match('/MSIE/',$_SERVER['HTTP_USER_AGENT'])) ? rawurlencode($subject) : $subject;

header('Content-type:application/vnd.ms-excel; charset=UTF-8');
header('Content-Disposition:attachment;filename='.$filename.'.xls');
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: none');
header('Content-type: application/force-download');

echo   $subject."\n\n";
echo   "用户 名\t";
echo   "真实姓名\t";
echo   "性别\t"; 
echo   "会员级别\t"; 
echo   "会员号\t";
echo   "证件类型\t";
echo   "证件号码\t"; 
echo   "联系手机\t"; 
//echo   "紧急联系人及联系方式\t";
echo   "血型\t";
//echo   "过敏史\t"; 
echo   "QQ\t"; 
echo   "MSN\t";
echo   "邮政编码\t";
echo   "通讯地址\t"; 
//echo   "其它信息\t"; 
//echo   "你是如何知晓本活动的\t";
//echo   "户外活动经验\t";
//echo   "租借装备\t"; 
echo   "备注说明\t"; 

//通过报名的会员列表
$query = DB::query('SELECT applyid, username, uid, verified, dateline, message, payment, ufielddata FROM '.DB::table('donkey_activity_apply').' WHERE verified=1 and tid='.$_G['gp_tid'].' ORDER BY dateline DESC');
loadcache('profilesetting');
while($activityapplies = DB::fetch($query)) {

$activityapplies['dateline'] = dgmdate($activityapplies['dateline'], 'u');
$activityapplies['ufielddata'] = unserialize($activityapplies['ufielddata']);
$ufielddata = '';
foreach($activityapplies['ufielddata'] as $k=>$fieldid) {
	$ufielddata .= '<li>'.$_G['cache']['profilesetting'][$k]['title'].'&nbsp;&nbsp;:&nbsp;&nbsp;'.$fieldid.'</li>';
}
$activityapplies['ufielddata'] = $ufielddata;
$activityapplies['message'] = preg_replace('/('.lang('forum/misc', 'contact').'.*)/', '', $activityapplies['message']);
$activityapplies['avatar'] = avatar($activityapplies['uid'], 'small');
$applylist[] = $activityapplies;

$user = DB::fetch_first('SELECT m.username, mp.realname, m.groupid, mp.gender, mp.telephone, mp.msn, mp.qq, mp.mobile, mp.idcardtype, mp.idcard, mp.bloodtype, mp.zipcode, mp.address FROM '.DB::table('common_member').' m, '.DB::table('common_member_profile').' mp WHERE m.uid='.$activityapplies['uid'].' and mp.uid='.$activityapplies['uid']);

$user['gender'] = get_gender($user['gender']);

echo   "\n\n";
echo_prop($user, 'username');
echo_prop($user, 'realname');
echo_prop($user, 'gender');
echo_prop($user, 'groupid');
echo_prop($activityapplies, 'uid');
echo_prop($user, 'idcardtype'); 
echo_prop($user, 'idcard');
echo_prop($user, 'telephone');
//echo_prop($apply, 'contact'); 
echo_prop($user, 'bloodtype');
//echo_prop($apply, 'guoming');
echo_prop($user, 'qq'); 
echo_prop($user, 'msn');
echo_prop($user, 'zipcode');
echo_prop($user, 'address'); 
//echo_prop($apply, 'extrainfo');
//echo_prop($apply, 'whyknow');
//echo_prop($apply, 'experience'); 
//echo_prop($apply, 'equipment');
echo_prop($activityapplies, 'message');  
}
?>